import pygame
from src.plants.seed import seed_card_img_map


class SeedCard:
    # 种子卡片对象
    __obj = None
    # 种子卡片 Rect 对象
    __rect = None
    # 种子图片名称
    __img_name = None
    # 种子图片
    __img = None
    # 种子卡片大小
    __size = None
    # 位置
    __position = None
    # 种子阳光价格
    __price = None

    def __init__(self, size, position, img=None, price=None):
        self.__size = size
        self.__position = position
        self.__img = img
        self.__obj = pygame.Surface(size)
        self.__obj.fill((255, 255, 255))
        self.__obj.set_alpha(20)
        self.set_img(img)
        self.__price = price

    def draw_to(self, target):
        self.__rect = target.blit(self.__obj, self.__position)

    def set_img(self, img):
        self.__img = img
        if img is not None:
            self.__img = pygame.transform.scale(self.__img, (self.__size[0], self.__size[1]))
            self.__obj.set_alpha(255)
            self.__obj.blit(self.__img, (0, 0))

    def set_img_name(self, img_name):
        if img_name is None or len(img_name) == 0:
            return
        self.__img_name = img_name
        self.set_img(seed_card_img_map.get(img_name))
